#include "PushButton.h"

int globalPushButtonPin = 8;

PushButton pb(globalPushButtonPin);

int globalLEDPin = 13;

void setup()
{
  pinMode(globalLEDPin, OUTPUT);
  
  digitalWrite(globalLEDPin, HIGH);
  delay(250);
  digitalWrite(globalLEDPin, LOW);
  delay(250);
  digitalWrite(globalLEDPin, HIGH);
  delay(250);
  digitalWrite(globalLEDPin, LOW);
}

void loop()
{
    switch(pb.Service())
    {
      case PushButton::SINGLE_PUSH:
        {
          digitalWrite(globalLEDPin, digitalRead(globalLEDPin) == HIGH ? LOW : HIGH);
        }
        break;
      case PushButton::CONSTANT_PUSH:
        {
            Blink(1000);
        }
        break;
      default:
        {
          // digitalWrite(globalLEDPin, LOW);
        }
        break;
    }
}

int globalDelayCounterMs = 0;

void Blink(int intervalMs)
{
  // if (globalBlinkEnabled)
  {
    int _currentCounterMs = millis();
    
    if ((_currentCounterMs - globalDelayCounterMs) > intervalMs)
    {
      digitalWrite(globalLEDPin, digitalRead(globalLEDPin) == HIGH ? LOW : HIGH);
      globalDelayCounterMs = _currentCounterMs;
    }
  }
}

